package SortAlgorithmPractice;

import java.util.Arrays;

public class InsertionSort {
    public static void main(String[] args) {
        int[] arr = {3,1,5,6,9,7,8,10};
        System.out.printf("Sort before : %s\n", Arrays.toString(arr));
        insertionSort(arr);
        System.out.printf("Sort after : %s\n", Arrays.toString(arr));
    }

    public static void insertionSort(int[] arr) {
        for (int i = 1; i <= arr.length - 1; i++) {
            int index = arr[i];
            int j = i - 1;
            while (j >=0 && arr[j] > index){
                arr[j+1] = arr[j];
                j--;
            }
            arr[j+1] = index;
        }
    }
}
